<extend name="./public/frame.html"/>
<block name="content">
    <form class="layui-form layui-form-pane1" method="post" enctype="multipart/form-data">
    <table class="layui-table">
        <tr>
            <td width="10%">申请用户号码</td>
            <td>{$data['old_phone']}</td>
        </tr>
        <tr>
            <td>申请更换号码</td>
            <td>{$data['new_phone']}</td>
        </tr>
        <tr>
            <td>申请更换理由</td>
            <td>{$data['phone_reason']}</td>
        </tr>
        <tr>
            <td>申请时间</td>
            <td>{$data['phone_reason']}</td>
        </tr>
        <tr>
            <td>审核状态</td>
            <td>{$data['checkResult']}</td>
        </tr>
        <?php if(!empty($data['phone_check_result'])):?>
        <tr>
            <td>审核信息</td>
            <td>{$data['result_reason']}</td>
        </tr>
        <tr>
            <td>审核人</td>
            <td>{$data['phone_check_person']}</td>
        </tr>
        <tr>
            <td>审核时间</td>
            <td>{$data['phone_check_time']}</td>
        </tr>
        <?php endif;?>
        <?php if(empty($data['phone_check_result'])):?>
        <tr>
            <td style="font-weight: bold;color: black; background:#F8F8F8" colspan="2">
                <input type="text" class="layui-input" readonly value="审核结果" style="border: 0px;width: 12%;float: left;background:#F8F8F8">
                <input type="checkbox" data-type="checkResult" lay-skin="switch" lay-filter="switchCheck" class="check" id="checkResult" lay-text="通过|未过" value="1" <?php if($data['phone_check_result'] == 2):?>checked<?php endif;?>>
                <input type="hidden" name="phone_check_result" id="phone_check_result" value="<?php if($data['phone_check_result'] == 0):?>1<?php else:?><?php echo $data['phone_check_result'];?><?php endif;?>">
            </td>
        </tr>
        <tr id="reason" class="reason">
            <td style="width: 10%;text-align: center;">未通过原因</td>
            <td>
                <textarea rows="3" class="layui-textarea" name="result_reason" id="result_reason"  maxlength="80" placeholder="请输入未通过原因"><?php echo $data['result_reason'];?></textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="padding-left: 100px;">
                <input type="hidden" value="<?php echo $data['id'];?>" name="id" id="id">
                <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </td>
        </tr>
        <?php endif;?>
    </table>
    </form>
    <script>
        layui.use(['form'], function () {
            var form = layui.form
                ,layer = layui.layer;
            form.on('switch(switchCheck)', function(data){
                if(!this.checked){
                    var value = 0;
                }else{
                    var value = 1;
                }
                var key_name = $(this).data('type');
                if(key_name == 'checkResult'){
                    if(value == 1){
                        $('#phone_check_result').val(2);
                    }else{
                        $('#phone_check_result').val(1);
                    }
                }
            });
            form.on('submit(*)', function(data){
                //点击通过
                if($("#checkResult:checked").val() != 2 && $("#result_reason").val() ==''){
                    layer.msg('请填写未通过原因',{icon: 5});return false;
                }
                $.ajax({
                    url:'{:url("/admin/User/updatePhone")}',
                    async:true,
                    dataType:'json',
                    type:'POST',
                    data: $(data.form).serialize(),
                    success:function(res){
                        if(res.code==1){
                            layer.alert(res.msg, {icon: 6},function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                window.parent.location.reload()
                            });
                        }else{
                            layer.msg(res.msg,{icon: 5});
                        }
                    }
                });
                return false;
            });
        });
    </script>
</block>
